<?php
if (isset($_SESSION['keranjang'])) {
	echo "<style type=\"text/css\">
		table {
			border-collapse: collapse;
		}
		table,th,td {
			padding: 5px;
			border: 1px solid black;
		}
		.table-judul {
			font-weight: bold;
			text-align: center;
		}
	</style>";
	if (isset($_SESSION['status-keranjang'])) {
		echo "<p>".$_SESSION['status-keranjang']."</p>";
		unset($_SESSION['status-keranjang']);
	}
	echo "<table><tbody>";
	foreach ($_SESSION['keranjang'] as $key=>$keranjang) {
		$produk = db_result("SELECT * FROM produk WHERE id = ".$keranjang['id']);
		echo "<tr><td><a href=\"".site()."/produk/".$produk['slug']."\">".$produk['nama']."</a></td><td>".$keranjang['kuantitas']."</td>";
		echo "<td><form action=\"".site()."/keranjang-action\" method=\"post\">";
		echo "<input type=\"hidden\" name=\"index\" value=\"".$key."\" />";
		echo "<input type=\"text\" name=\"kuantitas\" value=\"".$keranjang['kuantitas']."\" />";
		echo "<input type=\"submit\" name=\"update\" value=\"Update\" /></form></td>";
		echo "<td><form action=\"".site()."/keranjang-action\" method=\"post\">";
		echo "<input type=\"hidden\" name=\"index\" value=\"".$key."\" />";
		echo "<input type=\"submit\" name=\"hapus\" value=\"Hapus\" /></form></td></tr>";
	}
	echo "</tbody></table>";
	echo "<br><br><a href=\"".site()."/produk\">Pilih barang lain</a> -- <a href=\"".site()."/checkout\">Checkout</a>";
} else {
	if (isset($_SESSION['status-keranjang'])) unset($_SESSION['status-keranjang']);
	echo "Keranjang Anda kosong";
	echo "<br><br><a href=\"".site()."/produk\">Pilih barang lain</a>";
}
?>